#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution {
public:
    bool canPlaceFlowers(vector<int>& flowerbed, int n) {
        if(n==0){
            return true;
        }
        for(int i=0;i<flowerbed.size();++i){
            if(flowerbed[i]==0){
            if(i==0){
                if((i+1)<flowerbed.size()&&flowerbed[i+1]==0){
                    flowerbed[i] = 1;
                    --n;
                    if(n==0){
                        break;
                    }
                }            
                else if(i+1>=flowerbed.size()){
                    --n;
                     if(n==0){
                        break;
                    }
                }
            }
            else if((i==flowerbed.size()-1)){
                if(flowerbed[i-1]==0){
                    flowerbed[i] =1;
                    --n;
                     if(n==0){
                        break;
                    }
                }
            }
            else{
                if(flowerbed[i-1]==0&&flowerbed[i+1]==0){
                    flowerbed[i]=1;
                    --n;
                     if(n==0){
                        break;
                    }
                }
            }
            }
        }
        if(n==0){
            return true;
        }
        else{
            return false;
        }
    }
};

int main(){
    Solution S;
    vector<int> V = {0,0,1,0,0};
    cout<<S.canPlaceFlowers(V,1)<<endl;
}